Context state management for processor feature sets

ABSTRACT

Embodiments of an invention related to context state management based on processor features are disclosed. In one embodiment, a processor includes instruction logic and state management logic. The instruction logic is to receive a state management instruction having a parameter to identify a subset of the features supported by the processor. The state management logic is to perform a state management operation specified by the state management instruction.

FIELD

Embodiments of the invention relate to microprocessor architecture. Moreparticularly, embodiments of the invention relate to managing contextstate information within a microprocessor.

BACKGROUND

Modern microprocessors may perform numerous functions requiring a changeof context state. For example, a microprocessor may change context stateinformation when switching between groups of instructions, such assoftware threads. In changing between software threads, for example,context state of one group of instructions may be saved to a memorylocation and the context state of another group of instructions may berestored from memory and loaded into the microprocessor.

In reference to software threads, “context state” may refer to a portionof each software thread's state that is to be maintained between contextswitches within a processor. Context state may be stored in processorarchitectural registers, control registers, or other storage areas, suchas memory. Context state is typically represented by a number of bits,the values of which define a particular context state.

The term “context switch” typically refers to a change from oneprocessor execution state to another, such as a software thread switch.A context switch is typically performed either by the operating systemor by a user's program. For example, a context switch may occur as aresult of calling a subroutine within a user's program, in which thecalling program's context is saved in a storage area, such as a stackwhen the call to the subroutine occurs, and restored from the storagearea when returning from the called subroutine.

Typically, context state is saved to memory or restored to processorregisters in groups that may include more context state information thatis needed at a given time, due to the organization of context state saveareas in memory and the granularity with which these save areas areaddressed. As a result, an unnecessarily large number of processor stateinformation may be replaced each time context state is restored frommemory. For example, an operating system or user program may onlyrequest a subset of context state information pertaining to a particularsoftware thread or other process being performed within a processor.However, prior art context state save and restore mechanisms may requirethat all context state pertaining to a thread or other process berestored and/or saved in order to retrieve any context state informationpertaining to the thread or process of interest.

Prior art context state management techniques may, therefore, result inperformance and resource inefficiencies.

BRIEF DESCRIPTION OF THE DRAWINGS

Embodiments of the invention are illustrated by way of example and notlimitation in the figures of the accompanying drawings, in which likereferences indicate similar elements and in which:

FIG. 1 illustrates a system, memory, and processor supporting contextstate management according to an embodiment of the present invention.

FIG. 2 illustrates a method for context state management according to anembodiment of the present invention.

DETAILED DESCRIPTION

Embodiments of the invention pertain to microprocessor architecture.More particularly, embodiments of the invention pertain to managingprocessor context state. At least one embodiment of the inventionintroduces extended functionality to some prior art context statemanaging techniques in order to facilitate resource and performanceefficiency when reading and updating context state information within amicroprocessor.

An operating system (“OS”) and/or user program typically uses an area(“save area”) in a memory structure, such as dynamic random accessmemory (“DRAM”), for saving context state during a context switch. Inother prior art systems, some software routines, such as exceptionhandlers, may allocate the save area only as needed (“dynamically”) in amemory storage area, such as a stack. Instruction set architecturestypically define one or more instructions to handle the storage ofcontext state to memory or the restoration of context state from memory.For example, in one embodiment of the invention, two instructions,(“XSAVE” and “XRSTOR”) may be used to store context state to memory andrestore context state from a memory to a processor's registers,respectively. In other instruction set architectures more or fewer thantwo instructions may be used to manage context state information.

Embodiments of the present invention provide an approach to selectivelymanage processor context state, where the selectivity is on a perfeature basis. Embodiments provide for an approach that is independentof the feature set of a processor, therefore, it may be extended to newprocessor architectures.

FIG. 1 illustrates system 100, including memory 110 and processor 120,according to an embodiment of the present invention. Memory 110 andprocessor 120 may be coupled to or communicate with each other withinsystem 100 according to any known approach, such as directly orindirectly through one or more buses, point-to-point, or other wired orwireless connections. System 100 may also include any other componentsnot shown in FIG. 1.

Memory 110 may be static or dynamic random access memory, flash memory,magnetic or optical disk memory, any other type of medium readable byprocessor 120, or any combination of such mediums. Memory 110 includesstate save area 112 to save state of processor 120.

Processor 120 may be any type of processor, including a general purposemicroprocessor, such as a processor in the Intel® Pentium® ProcessorFamily, Itanium® Processor Family, or other processor family from Intel®Corporation, or another processor from another company, or a specialpurpose processor or microcontroller. Processor 120 may include multiplethreads and multiple execution cores, in any combination. Processor 120includes instruction logic 122 and state management logic 124. Processor120 may also include any other circuitry, structures, or logic not shownin FIG. 1.

Instruction logic 122 is to receive instructions, including statemanagement instructions. State management instructions may be anyinstructions to which the processor is designed to respond by performingstate management operations, as described below. Instruction logic 122may include any circuitry, logic, or other structure that recognizes,decodes, or otherwise receives instructions.

Stage management logic 124 is to perform state management operations, asdescribed below. State management logic 124 may include any circuitry,logic, or other structures to perform the state management operations.For example, state management logic 124 may include microcode, statemachine logic, programmable logic, or any other form of control logic tocause processor 120 to respond appropriately to state managementinstructions. To do so, state management logic 124 may refer to any formof hardware, software, or firmware, such as a processor abstractionlayer, within processor 120 or within any device accessible or mediumreadable by processor 120, such as memory 110.

Also, state management logic may include logic and datapaths to read,write, and move state information into, from, and between registers andother storage locations where state information may be stored forinternal use and/or to be read by software running on processor 120, andlogic to perform masking and other logical operations on bit vectors orother representations of state information. State management logic 124may be dedicated to state management or may by used, in whole, in part,and/or together with other logic, to perform other functions,operations, instructions, etc. in processor 120.

State management logic 124 may determine what operation to perform andhow to perform the operation based on information provided by theinstruction, associated with the instruction, and/or related to otherinformation accessible by state management logic 124. Any known approachto conveying this information from software to state management logic124 may be used within the scope of the present invention, such as anycombination of different instructions, different instruction formats,different operand types and locations, etc. For example, statemanagement instructions may include a field holding the information, thename of a register holding the information, and/or an address of amemory location holding the information. According to any of theseapproaches, or any other known approach, the information may be referredto as a “parameter” of the instruction.

State management logic 124 may operate based on signals from instructionlogic 122, and/or based on any parameters associated with a statemanagement instruction, to cause processor 120 to execute portions ofmethod embodiments of the present invention, such as method 200 and 300,as illustrated in FIG. 2. For example, control logic 124 may causeprocessor 120 to execute portions of method embodiments of the presentinvention by executing one or more micro-instructions ormicro-operations in response to receiving a state managementinstruction.

FIG. 2 illustrates method 200 for processor state management accordingto an embodiment of the present invention. Although method embodimentsof the invention are not limited in this respect, reference may be madeto elements of system 100 to describe the method embodiment of FIG. 2.Method 200 refers to state management instructions by names that may beused according to one embodiment; in other embodiments, theseinstructions or similar instructions may have different names.

In box 210 of method 200, a processor is queried, e.g., by an OS issuinga processor identification (“CPUID”) instruction with an appropriaterequest type and/or other parameters, to enumerate the featuressupported by the processor. In box 220, the OS or other privilegedsoftware enables a subset of those features.

In box 230, the OS issues an instruction (“XSETBV”) to convey to thestate management logic the subset of the features that are enabled. Inone embodiment, XSETBV has a parameter to program a bit vector(“XFEATURE_ENABLED_MASK”) to indicate which features are enabled, e.g.,using one bit per feature that has a manageable state. A correspondinginstruction (“XGETBV”) may be used by software to readXFEATURE_ENABLED_MASK.

The XSETBV and XGETBV instructions also may have a parameter to allowthem to be used to program and read, respectively, two other bitvectors. One of these bit vectors indicates which features are currentlyin use, i.e., their state values might have changed sinceinitialization. The other of these bit vectors indicates which featuresare currently modified, i.e., their state values might have changedsince the last their state was last restored. XSETBV may be a privilegedinstruction and XBVGET may be a non-privileged instruction.

In box 240, the processor is queried, e.g., by an OS issuing CPUID withan appropriate request type and/or other parameters, to determine thesize required for the state save area, based on the enabled features. ACPUID instruction may also be used to determine the size required forthe state save area if all features are enabled. Another instruction(“XSIZE”) may be used, with a bit vector indicating a subset of featuresas a parameter, to determine the size required for that subset.

In box 250, the OS may allocate a portion of memory for the state savearea. In box 260, the OS may issue an instruction (“XSAVE”) to save thecurrent context. In box 270, the OS may issue an instruction (“XRSTOR”)to restore a saved context. Upon execution of XRSTOR, all state may bemarked as unmodified.

XSAVE and XRSTOR may have a parameter that provide for selectivelycontrolling the saving and restoring of state. The parameter may be abit vector, with one bit per feature, to select the features for whichstate should be saved or restored. This bit vector may be combined withXFEATURE_ENABLED_MASK (e.g., with a logical AND operation) by statemanagement logic, such that state is saved or restored only for thosefeatures that are both selected and enabled.

Within the scope of the present invention, the method illustrated inFIG. 2 may be performed in a different order, with illustrated boxesomitted, with additional boxes added, or with a combination ofreordered, omitted, or additional boxes. Many variations of method 200and many other methods are possible within the scope of the presentinvention. Some of these variations or other methods may be based on thefollowing descriptions that may be included in other embodiments of thepresent invention.

Another save instruction (“XSAVEOPT”) may be used to provide for moreoptimal state management. XSAVEOPT may be architecturally compatiblewith XSAVE, in that XRSTOR may be used with either. In one embodiment,XSAVEOPT may be used by an OS and XSAVE by other software. XSAVEOPT may,implicitly or by using a parameter, specify that only the state for thefeatures with currently in-use state should be saved, or, that only thestate for features with currently modified state should be saved. Tofacilitate operation of XSAVEOPT, an identifier for XRSTOR, e.g., thesave area address, may be recorded in the processor (not readable bysoftware). Then, all state corresponding to the logical AND ofXFEATURE_ENABLED_MASK and the in-use mask or the modified mask from thesave area header may restored.

A header in the save area records may indicate whether each component ofthe state is valid in the save image. A value of “1” in the header mayindicate that the data associated with that bit in the save image isvalid (e.g., data has been saved there). A value of “0” in the headermay indicate that the state associated with that bit is in itsinitialized form and the memory area corresponding to the bit may notcontain the initialized value of that state. Execution of XRSTOR mayrefer to this header to properly initialize state for which the saveimage is not valid.

All state may be marked as modified based on an indication of a contextswitch (e.g., a change to a page table pointer register), a transfer ofcontrol to or from a virtual machine, or when a feature set is changed.

An optional parameter to XSAVE and XRSTOR may specify that the statesave area for features that are not to be saved or restored should becompacted out.

An instruction (“XOFFSET”) may be used to determine the location of agiven feature's state within a save image. XOFFSET may have a parameter(e.g., a bit vector) to indicate the features saved by the last save tothat image, and another parameter (e.g., an index into the bit vector)to identify the given feature.

Embodiments of the present invention provide for extensibility to newfeature sets. New features may be appended to currently-defined state.New features may get an additional element in a feature bit vector inthe header. The position of a feature in the feature bit vector does notimply an ordering in the state save area.

Processor 100, or any other component or portion of a component designedaccording to an embodiment of the present invention, may be designed invarious stages, from creation to simulation to fabrication. Datarepresenting a design may represent the design in a number of manners.First, as is useful in simulations, the hardware may be representedusing a hardware description language or another functional descriptionlanguage. Additionally or alternatively, a circuit level model withlogic and/or transistor gates may be produced at some stages of thedesign process. Furthermore, most designs, at some stage, reach a levelwhere they may be modeled with data representing the physical placementof various devices. In the case where conventional semiconductorfabrication techniques are used, the data representing the deviceplacement model may be the data specifying the presence or absence ofvarious features on different mask layers for masks used to produce anintegrated circuit.

In any representation of the design, the data may be stored in any formof a machine-readable medium. An optical or electrical wave modulated orotherwise generated to transmit such information, a memory, or amagnetic or optical storage medium, such as a disc, may be themachine-readable medium. Any of these media may “carry” or “indicate”the design, or other information used in an embodiment of the presentinvention. When an electrical carrier wave indicating or carrying theinformation is transmitted, to the extent that copying, buffering, orre-transmission of the electrical signal is performed, a new copy ismade. Thus, the actions of a communication provider or a networkprovider may constitute the making of copies of an article, e.g., acarrier wave, embodying techniques of the present invention.

Thus, embodiments of an invention related to context state managementbased on processor features have been described. While certainembodiments have been described, and shown in the accompanying drawings,it is to be understood that such embodiments are merely illustrative andnot restrictive of the broad invention, and that this invention not belimited to the specific constructions and arrangements shown anddescribed, since various other modifications may occur to thoseordinarily skilled in the art upon studying this disclosure. In an areaof technology such as this, where growth is fast and furtheradvancements are not easily foreseen, the disclosed embodiments may bereadily modifiable in arrangement and detail as facilitated by enablingtechnological advancements without departing from the principles of thepresent disclosure or the scope of the accompanying claims.

1. A processor comprising: instruction logic to receive a statemanagement instruction having a parameter to identify a subset of aplurality of features supported by the processor; and state managementlogic to perform a state management operation specified by the statemanagement instruction.
 2. The processor of claim 1, wherein theparameter indicates the features that are enabled.
 3. The processor ofclaim 1, wherein the parameter indicates the features that are selectedfor state management.
 4. The processor of claim 1, wherein the statemanagement logic is to perform the state management operation for thesubset of the plurality of features.
 5. The processor of claim 1,wherein the state management logic is to perform the state managementoperation for the enabled features in the subset of the plurality offeatures.
 6. The processor of claim 1, wherein the state managementoperation is to convey to the state management logic the features thatare enabled.
 7. The processor of claim 1, wherein the state managementoperation is to save a context.
 8. The processor of claim 1, wherein thestate management operation is to restore a context.
 9. The processor ofclaim 7, wherein the state management operation is to save only in-usestate.
 10. The processor of claim 7, wherein the state managementoperation is to save only modified state.
 11. The processor of claim 8,wherein the state management operation is to restore only valid state.12. A method comprising: receiving, by a processor, a state managementinstruction having a parameter to identify a subset of a plurality offeatures supported by the processor; and performing, by the processor, astate management operation specified by the state managementinstruction.
 13. The method of claim 12, wherein the state managementoperation is to save a context.
 14. The method of claim 12, wherein thestate management operation is to restore a context.
 15. The method ofclaim 12, wherein the parameter indicates the features that are enabled.16. The method of claim 12, wherein the parameter indicates the featuresthat are selected for state management.
 17. The method of claim 12,wherein the state management logic is to perform the state managementoperation for the subset of the plurality of features.
 18. The method ofclaim 12, wherein the state management logic is to perform the statemanagement operation for the enabled features in the subset of theplurality of features.
 19. The method of claim 12, wherein the statemanagement operation is to convey to the state management logic thefeatures that are enabled.
 20. A system comprising: a memory to storestate; and a processor including: instruction logic to receive a statemanagement instruction having a parameter to identify a subset of aplurality of features supported by the processor; and state managementlogic to perform one of an operation to save state for the subset to thememory and an operation to restore state for the subset from the memory.